package zhongbo.java.air.monitor.web.websocket;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;

/**
 * @ClassName PathWebSocket
 * @Description 将收到的实时航迹信息广播给所有websocket客户端
 * @Author 琪
 * @Date 2025/4/7 00:24
 */

@ServerEndpoint(value = "/websocket/live")
@Component
@Slf4j
public class PathWebSocket {

    public PathWebSocket() {
        System.out.println("载入 PathWebSocket 构造方法");
    }


    @OnOpen
    public void onOpen(Session session) {
        WebSocketSessionManager.addSession(session);
    }

    @OnClose
    public void onClose(Session session, CloseReason reason) {
        WebSocketSessionManager.removeSession(session, reason);
    }

    @OnError
    public void onError(Session session, Throwable error) {
        error.printStackTrace();
    }


    /*
    html 客户端代码:
    var wsClient = new WebSocket('ws://localhost:8080/chat1/zhangsan/99999')
    wsClient.send('你好吗?')
    wsClient.close()
     */

}
